
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Compose 模板文件 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="django.html" />
    
    
    <link rel="prev" href="commands.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../CHANGELOG.md">
            
                <span>
            
                    
                    修订记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../CONTRIBUTING.md">
            
                <span>
            
                    
                    如何贡献
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../introduction/">
            
                <a href="../introduction/">
            
                    
                    Docker 简介
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../introduction/what.html">
            
                <a href="../introduction/what.html">
            
                    
                    什么是 Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../introduction/why.html">
            
                <a href="../introduction/why.html">
            
                    
                    为什么要用 Docker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../basic_concept/">
            
                <a href="../basic_concept/">
            
                    
                    基本概念
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../basic_concept/image.html">
            
                <a href="../basic_concept/image.html">
            
                    
                    镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../basic_concept/container.html">
            
                <a href="../basic_concept/container.html">
            
                    
                    容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../basic_concept/repository.html">
            
                <a href="../basic_concept/repository.html">
            
                    
                    仓库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../install/">
            
                <a href="../install/">
            
                    
                    安装 Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../install/ubuntu.html">
            
                <a href="../install/ubuntu.html">
            
                    
                    Ubuntu
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../install/debian.html">
            
                <a href="../install/debian.html">
            
                    
                    Debian
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../install/fedora.html">
            
                <a href="../install/fedora.html">
            
                    
                    Fedora
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../install/centos.html">
            
                <a href="../install/centos.html">
            
                    
                    CentOS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../install/raspberry-pi.html">
            
                <a href="../install/raspberry-pi.html">
            
                    
                    Raspberry Pi
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../install/mac.html">
            
                <a href="../install/mac.html">
            
                    
                    macOS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../install/windows.html">
            
                <a href="../install/windows.html">
            
                    
                    Windows 10
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../install/mirror.html">
            
                <a href="../install/mirror.html">
            
                    
                    镜像加速器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../install/experimental.html">
            
                <a href="../install/experimental.html">
            
                    
                    开启实验特性
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../image/">
            
                <a href="../image/">
            
                    
                    使用镜像
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../image/pull.html">
            
                <a href="../image/pull.html">
            
                    
                    获取镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../image/list.html">
            
                <a href="../image/list.html">
            
                    
                    列出镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../image/rm.html">
            
                <a href="../image/rm.html">
            
                    
                    删除本地镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../image/commit.html">
            
                <a href="../image/commit.html">
            
                    
                    利用 commit 理解镜像构成
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../image/build.html">
            
                <a href="../image/build.html">
            
                    
                    使用 Dockerfile 定制镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../image/dockerfile/">
            
                <a href="../image/dockerfile/">
            
                    
                    Dockerfile 指令详解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.6.1" data-path="../image/dockerfile/copy.html">
            
                <a href="../image/dockerfile/copy.html">
            
                    
                    COPY 复制文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.2" data-path="../image/dockerfile/add.html">
            
                <a href="../image/dockerfile/add.html">
            
                    
                    ADD 更高级的复制文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.3" data-path="../image/dockerfile/cmd.html">
            
                <a href="../image/dockerfile/cmd.html">
            
                    
                    CMD 容器启动命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.4" data-path="../image/dockerfile/entrypoint.html">
            
                <a href="../image/dockerfile/entrypoint.html">
            
                    
                    ENTRYPOINT 入口点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.5" data-path="../image/dockerfile/env.html">
            
                <a href="../image/dockerfile/env.html">
            
                    
                    ENV 设置环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.6" data-path="../image/dockerfile/arg.html">
            
                <a href="../image/dockerfile/arg.html">
            
                    
                    ARG 构建参数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.7" data-path="../image/dockerfile/volume.html">
            
                <a href="../image/dockerfile/volume.html">
            
                    
                    VOLUME 定义匿名卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.8" data-path="../image/dockerfile/expose.html">
            
                <a href="../image/dockerfile/expose.html">
            
                    
                    EXPOSE 暴露端口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.9" data-path="../image/dockerfile/workdir.html">
            
                <a href="../image/dockerfile/workdir.html">
            
                    
                    WORKDIR 指定工作目录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.10" data-path="../image/dockerfile/user.html">
            
                <a href="../image/dockerfile/user.html">
            
                    
                    USER 指定当前用户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.11" data-path="../image/dockerfile/healthcheck.html">
            
                <a href="../image/dockerfile/healthcheck.html">
            
                    
                    HEALTHCHECK 健康检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.12" data-path="../image/dockerfile/onbuild.html">
            
                <a href="../image/dockerfile/onbuild.html">
            
                    
                    ONBUILD 为他人作嫁衣裳
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6.13" data-path="../image/dockerfile/references.html">
            
                <a href="../image/dockerfile/references.html">
            
                    
                    参考文档
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../image/multistage-builds/">
            
                <a href="../image/multistage-builds/">
            
                    
                    Dockerfile 多阶段构建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.7.1" data-path="../image/multistage-builds/laravel.html">
            
                <a href="../image/multistage-builds/laravel.html">
            
                    
                    实战多阶段构建 Laravel 镜像
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../image/manifest.html">
            
                <a href="../image/manifest.html">
            
                    
                    构建多种系统架构支持的 Docker 镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../image/other.html">
            
                <a href="../image/other.html">
            
                    
                    其它制作镜像的方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../image/internal.html">
            
                <a href="../image/internal.html">
            
                    
                    实现原理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../container/">
            
                <a href="../container/">
            
                    
                    操作容器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../container/run.html">
            
                <a href="../container/run.html">
            
                    
                    启动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../container/daemon.html">
            
                <a href="../container/daemon.html">
            
                    
                    守护态运行
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../container/stop.html">
            
                <a href="../container/stop.html">
            
                    
                    终止
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../container/attach_exec.html">
            
                <a href="../container/attach_exec.html">
            
                    
                    进入容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../container/import_export.html">
            
                <a href="../container/import_export.html">
            
                    
                    导出和导入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../container/rm.html">
            
                <a href="../container/rm.html">
            
                    
                    删除
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../repository/">
            
                <a href="../repository/">
            
                    
                    访问仓库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../repository/dockerhub.html">
            
                <a href="../repository/dockerhub.html">
            
                    
                    Docker Hub
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../repository/registry.html">
            
                <a href="../repository/registry.html">
            
                    
                    私有仓库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../repository/registry_auth.html">
            
                <a href="../repository/registry_auth.html">
            
                    
                    私有仓库高级配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../repository/nexus3_registry.html">
            
                <a href="../repository/nexus3_registry.html">
            
                    
                    Nexus 3
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../data_management/">
            
                <a href="../data_management/">
            
                    
                    数据管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../data_management/volume.html">
            
                <a href="../data_management/volume.html">
            
                    
                    数据卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../data_management/bind-mounts.html">
            
                <a href="../data_management/bind-mounts.html">
            
                    
                    挂载主机目录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../network/">
            
                <a href="../network/">
            
                    
                    使用网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../network/port_mapping.html">
            
                <a href="../network/port_mapping.html">
            
                    
                    外部访问容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../network/linking.html">
            
                <a href="../network/linking.html">
            
                    
                    容器互联
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../network/dns.html">
            
                <a href="../network/dns.html">
            
                    
                    配置 DNS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../advanced_network/">
            
                <a href="../advanced_network/">
            
                    
                    高级网络配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../advanced_network/quick_guide.html">
            
                <a href="../advanced_network/quick_guide.html">
            
                    
                    快速配置指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../advanced_network/access_control.html">
            
                <a href="../advanced_network/access_control.html">
            
                    
                    容器访问控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../advanced_network/port_mapping.html">
            
                <a href="../advanced_network/port_mapping.html">
            
                    
                    端口映射实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../advanced_network/docker0.html">
            
                <a href="../advanced_network/docker0.html">
            
                    
                    配置 docker0 网桥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../advanced_network/bridge.html">
            
                <a href="../advanced_network/bridge.html">
            
                    
                    自定义网桥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../advanced_network/example.html">
            
                <a href="../advanced_network/example.html">
            
                    
                    工具和示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.7" data-path="../advanced_network/config_file.html">
            
                <a href="../advanced_network/config_file.html">
            
                    
                    编辑网络配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.8" data-path="../advanced_network/ptp.html">
            
                <a href="../advanced_network/ptp.html">
            
                    
                    实例：创建一个点到点连接
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../buildx/">
            
                <a href="../buildx/">
            
                    
                    Docker Buildx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../buildx/buildkit.html">
            
                <a href="../buildx/buildkit.html">
            
                    
                    BuildKit
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../buildx/buildx.html">
            
                <a href="../buildx/buildx.html">
            
                    
                    使用 buildx 构建镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../buildx/multi-arch-images.html">
            
                <a href="../buildx/multi-arch-images.html">
            
                    
                    使用 buildx 构建多种系统架构支持的 Docker 镜像
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="./">
            
                <a href="./">
            
                    
                    Docker Compose
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="introduction.html">
            
                <a href="introduction.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="install.html">
            
                <a href="install.html">
            
                    
                    安装与卸载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="usage.html">
            
                <a href="usage.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="commands.html">
            
                <a href="commands.html">
            
                    
                    命令说明
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.14.5" data-path="compose_file.html">
            
                <a href="compose_file.html">
            
                    
                    Compose 模板文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.6" data-path="django.html">
            
                <a href="django.html">
            
                    
                    实战 Django
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.7" data-path="rails.html">
            
                <a href="rails.html">
            
                    
                    实战 Rails
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.8" data-path="wordpress.html">
            
                <a href="wordpress.html">
            
                    
                    实战 WordPress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.9" data-path="lnmp.html">
            
                <a href="lnmp.html">
            
                    
                    实战 LNMP
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../swarm_mode/">
            
                <a href="../swarm_mode/">
            
                    
                    Swarm mode
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../swarm_mode/overview.html">
            
                <a href="../swarm_mode/overview.html">
            
                    
                    基本概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../swarm_mode/create.html">
            
                <a href="../swarm_mode/create.html">
            
                    
                    创建 Swarm 集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../swarm_mode/deploy.html">
            
                <a href="../swarm_mode/deploy.html">
            
                    
                    部署服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../swarm_mode/stack.html">
            
                <a href="../swarm_mode/stack.html">
            
                    
                    使用 compose 文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.5" data-path="../swarm_mode/secret.html">
            
                <a href="../swarm_mode/secret.html">
            
                    
                    管理密钥
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.6" data-path="../swarm_mode/config.html">
            
                <a href="../swarm_mode/config.html">
            
                    
                    管理配置信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.7" data-path="../swarm_mode/rolling_update.html">
            
                <a href="../swarm_mode/rolling_update.html">
            
                    
                    滚动升级
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../security/">
            
                <a href="../security/">
            
                    
                    安全
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../security/kernel_ns.html">
            
                <a href="../security/kernel_ns.html">
            
                    
                    内核命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../security/control_group.html">
            
                <a href="../security/control_group.html">
            
                    
                    控制组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../security/daemon_sec.html">
            
                <a href="../security/daemon_sec.html">
            
                    
                    服务端防护
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.4" data-path="../security/kernel_capability.html">
            
                <a href="../security/kernel_capability.html">
            
                    
                    内核能力机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.5" data-path="../security/other_feature.html">
            
                <a href="../security/other_feature.html">
            
                    
                    其它安全特性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.6" data-path="../security/summary.html">
            
                <a href="../security/summary.html">
            
                    
                    总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../underly/">
            
                <a href="../underly/">
            
                    
                    底层实现
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../underly/arch.html">
            
                <a href="../underly/arch.html">
            
                    
                    基本架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../underly/namespace.html">
            
                <a href="../underly/namespace.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../underly/cgroups.html">
            
                <a href="../underly/cgroups.html">
            
                    
                    控制组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../underly/ufs.html">
            
                <a href="../underly/ufs.html">
            
                    
                    联合文件系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5" data-path="../underly/container_format.html">
            
                <a href="../underly/container_format.html">
            
                    
                    容器格式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.6" data-path="../underly/network.html">
            
                <a href="../underly/network.html">
            
                    
                    网络
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../etcd/">
            
                <a href="../etcd/">
            
                    
                    Etcd 项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.18.1" data-path="../etcd/intro.html">
            
                <a href="../etcd/intro.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="../etcd/install.html">
            
                <a href="../etcd/install.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="../etcd/cluster.html">
            
                <a href="../etcd/cluster.html">
            
                    
                    集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.4" data-path="../etcd/etcdctl.html">
            
                <a href="../etcd/etcdctl.html">
            
                    
                    使用 etcdctl
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../coreos/">
            
                <a href="../coreos/">
            
                    
                    Fedora CoreOS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.19.1" data-path="../coreos/intro.html">
            
                <a href="../coreos/intro.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19.2" data-path="../coreos/install.html">
            
                <a href="../coreos/install.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../kubernetes/">
            
                <a href="../kubernetes/">
            
                    
                    Kubernetes - 开源容器编排引擎
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.20.1" data-path="../kubernetes/intro.html">
            
                <a href="../kubernetes/intro.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20.2" data-path="../kubernetes/concepts.html">
            
                <a href="../kubernetes/concepts.html">
            
                    
                    基本概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20.3" data-path="../kubernetes/design.html">
            
                <a href="../kubernetes/design.html">
            
                    
                    架构设计
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../kubernetes/setup/">
            
                <a href="../kubernetes/setup/">
            
                    
                    部署 Kubernetes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.21.1" data-path="../kubernetes/setup/kubeadm.html">
            
                <a href="../kubernetes/setup/kubeadm.html">
            
                    
                    使用 kubeadm 部署 kubernetes
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21.2" data-path="../kubernetes/setup/docker-desktop.html">
            
                <a href="../kubernetes/setup/docker-desktop.html">
            
                    
                    在 Docker Desktop 使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21.3" data-path="../kubernetes/setup/systemd.html">
            
                <a href="../kubernetes/setup/systemd.html">
            
                    
                    一步步部署 kubernetes 集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21.4" data-path="../kubernetes/setup/dashboard.html">
            
                <a href="../kubernetes/setup/dashboard.html">
            
                    
                    部署 Dashboard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="../kubernetes/kubectl/">
            
                <a href="../kubernetes/kubectl/">
            
                    
                    Kubernetes 命令行 kubectl
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="../cloud/">
            
                <a href="../cloud/">
            
                    
                    容器与云计算
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.23.1" data-path="../cloud/intro.html">
            
                <a href="../cloud/intro.html">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23.2" data-path="../cloud/tencentCloud.html">
            
                <a href="../cloud/tencentCloud.html">
            
                    
                    腾讯云
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23.3" data-path="../cloud/alicloud.html">
            
                <a href="../cloud/alicloud.html">
            
                    
                    阿里云
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23.4" data-path="../cloud/aws.html">
            
                <a href="../cloud/aws.html">
            
                    
                    亚马逊云
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23.5" data-path="../cloud/summary.html">
            
                <a href="../cloud/summary.html">
            
                    
                    小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="../cases/os/">
            
                <a href="../cases/os/">
            
                    
                    实战案例 - 操作系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.24.1" data-path="../cases/os/busybox.html">
            
                <a href="../cases/os/busybox.html">
            
                    
                    Busybox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24.2" data-path="../cases/os/alpine.html">
            
                <a href="../cases/os/alpine.html">
            
                    
                    Alpine
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24.3" data-path="../cases/os/debian.html">
            
                <a href="../cases/os/debian.html">
            
                    
                    Debian Ubuntu
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24.4" data-path="../cases/os/centos.html">
            
                <a href="../cases/os/centos.html">
            
                    
                    CentOS Fedora
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24.5" data-path="../cases/os/summary.html">
            
                <a href="../cases/os/summary.html">
            
                    
                    本章小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="../cases/ci/">
            
                <a href="../cases/ci/">
            
                    
                    实战案例 - CI/CD
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.25.1" data-path="../cases/ci/actions/">
            
                <a href="../cases/ci/actions/">
            
                    
                    GitHub Actions
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25.2" data-path="../cases/ci/drone/">
            
                <a href="../cases/ci/drone/">
            
                    
                    Drone
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.25.2.1" data-path="../cases/ci/drone/install.html">
            
                <a href="../cases/ci/drone/install.html">
            
                    
                    部署 Drone
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.25.3" data-path="../cases/ci/travis/">
            
                <a href="../cases/ci/travis/">
            
                    
                    Travis CI
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="../IDE/">
            
                <a href="../IDE/">
            
                    
                    在 IDE 中使用 Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.26.1" data-path="../IDE/vsCode.html">
            
                <a href="../IDE/vsCode.html">
            
                    
                    VS Code
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.27" data-path="../opensource/">
            
                <a href="../opensource/">
            
                    
                    Docker 开源项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.27.1" data-path="../opensource/linuxkit.html">
            
                <a href="../opensource/linuxkit.html">
            
                    
                    LinuxKit
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="../podman/">
            
                <a href="../podman/">
            
                    
                    podman - 下一代 Linux 容器工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29" data-path="../appendix/">
            
                <a href="../appendix/">
            
                    
                    附录
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.29.1" data-path="../appendix/faq/">
            
                <a href="../appendix/faq/">
            
                    
                    附录一：常见问题总结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2" data-path="../appendix/repo/">
            
                <a href="../appendix/repo/">
            
                    
                    附录二：热门镜像介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.29.2.1" data-path="../appendix/repo/ubuntu.html">
            
                <a href="../appendix/repo/ubuntu.html">
            
                    
                    Ubuntu
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.2" data-path="../appendix/repo/centos.html">
            
                <a href="../appendix/repo/centos.html">
            
                    
                    CentOS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.3" data-path="../appendix/repo/nginx.html">
            
                <a href="../appendix/repo/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.4" data-path="../appendix/repo/php.html">
            
                <a href="../appendix/repo/php.html">
            
                    
                    PHP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.5" data-path="../appendix/repo/nodejs.html">
            
                <a href="../appendix/repo/nodejs.html">
            
                    
                    Node.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.6" data-path="../appendix/repo/mysql.html">
            
                <a href="../appendix/repo/mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.7" data-path="../appendix/repo/wordpress.html">
            
                <a href="../appendix/repo/wordpress.html">
            
                    
                    WordPress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.8" data-path="../appendix/repo/mongodb.html">
            
                <a href="../appendix/repo/mongodb.html">
            
                    
                    MongoDB
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.2.9" data-path="../appendix/repo/redis.html">
            
                <a href="../appendix/repo/redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.29.3" data-path="../appendix/command/">
            
                <a href="../appendix/command/">
            
                    
                    附录三：Docker 命令查询
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.29.3.1" data-path="../appendix/command/docker.html">
            
                <a href="../appendix/command/docker.html">
            
                    
                    客户端命令 - docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.3.2" data-path="../appendix/command/dockerd.html">
            
                <a href="../appendix/command/dockerd.html">
            
                    
                    服务端命令 - dockerd
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.29.4" data-path="../appendix/best_practices.html">
            
                <a href="../appendix/best_practices.html">
            
                    
                    附录四：Dockerfile 最佳实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.5" data-path="../appendix/debug.html">
            
                <a href="../appendix/debug.html">
            
                    
                    附录五：如何调试 Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29.6" data-path="../appendix/resources.html">
            
                <a href="../appendix/resources.html">
            
                    
                    附录六：资源链接
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.30" data-path="../archive/">
            
                <a href="../archive/">
            
                    
                    归档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.30.1" data-path="../mesos/">
            
                <a href="../mesos/">
            
                    
                    Mesos - 优秀的集群资源调度平台
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.30.1.1" data-path="../mesos/intro.html">
            
                <a href="../mesos/intro.html">
            
                    
                    Mesos 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.1.2" data-path="../mesos/installation.html">
            
                <a href="../mesos/installation.html">
            
                    
                    安装与使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.1.3" data-path="../mesos/architecture.html">
            
                <a href="../mesos/architecture.html">
            
                    
                    原理与架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.1.4" data-path="../mesos/configuration.html">
            
                <a href="../mesos/configuration.html">
            
                    
                    Mesos 配置项解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.1.5" data-path="../mesos/monitor.html">
            
                <a href="../mesos/monitor.html">
            
                    
                    日志与监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.1.6" data-path="../mesos/framework.html">
            
                <a href="../mesos/framework.html">
            
                    
                    常见应用框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.1.7" data-path="../mesos/summary.html">
            
                <a href="../mesos/summary.html">
            
                    
                    本章小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.30.2" data-path="../machine/">
            
                <a href="../machine/">
            
                    
                    Docker Machine
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.30.2.1" data-path="../machine/install.html">
            
                <a href="../machine/install.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30.2.2" data-path="../machine/usage.html">
            
                <a href="../machine/usage.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.30.3" data-path="../swarm/">
            
                <a href="../swarm/">
            
                    
                    Docker Swarm
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Compose 模板文件</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="compose-&#x6A21;&#x677F;&#x6587;&#x4EF6;">Compose &#x6A21;&#x677F;&#x6587;&#x4EF6;</h1>
<p>&#x6A21;&#x677F;&#x6587;&#x4EF6;&#x662F;&#x4F7F;&#x7528; <code>Compose</code> &#x7684;&#x6838;&#x5FC3;&#xFF0C;&#x6D89;&#x53CA;&#x5230;&#x7684;&#x6307;&#x4EE4;&#x5173;&#x952E;&#x5B57;&#x4E5F;&#x6BD4;&#x8F83;&#x591A;&#x3002;&#x4F46;&#x5927;&#x5BB6;&#x4E0D;&#x7528;&#x62C5;&#x5FC3;&#xFF0C;&#x8FD9;&#x91CC;&#x9762;&#x5927;&#x90E8;&#x5206;&#x6307;&#x4EE4;&#x8DDF; <code>docker run</code> &#x76F8;&#x5173;&#x53C2;&#x6570;&#x7684;&#x542B;&#x4E49;&#x90FD;&#x662F;&#x7C7B;&#x4F3C;&#x7684;&#x3002;</p>
<p>&#x9ED8;&#x8BA4;&#x7684;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#x540D;&#x79F0;&#x4E3A; <code>docker-compose.yml</code>&#xFF0C;&#x683C;&#x5F0F;&#x4E3A; YAML &#x683C;&#x5F0F;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&quot;3&quot;</span>

<span class="hljs-attr">services:</span>
<span class="hljs-attr">  webapp:</span>
<span class="hljs-attr">    image:</span> examples/web
<span class="hljs-attr">    ports:</span>
<span class="hljs-bullet">      -</span> <span class="hljs-string">&quot;80:80&quot;</span>
<span class="hljs-attr">    volumes:</span>
<span class="hljs-bullet">      -</span> <span class="hljs-string">&quot;/data&quot;</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#x6BCF;&#x4E2A;&#x670D;&#x52A1;&#x90FD;&#x5FC5;&#x987B;&#x901A;&#x8FC7; <code>image</code> &#x6307;&#x4EE4;&#x6307;&#x5B9A;&#x955C;&#x50CF;&#x6216; <code>build</code> &#x6307;&#x4EE4;&#xFF08;&#x9700;&#x8981; Dockerfile&#xFF09;&#x7B49;&#x6765;&#x81EA;&#x52A8;&#x6784;&#x5EFA;&#x751F;&#x6210;&#x955C;&#x50CF;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F7F;&#x7528; <code>build</code> &#x6307;&#x4EE4;&#xFF0C;&#x5728; <code>Dockerfile</code> &#x4E2D;&#x8BBE;&#x7F6E;&#x7684;&#x9009;&#x9879;(&#x4F8B;&#x5982;&#xFF1A;<code>CMD</code>, <code>EXPOSE</code>, <code>VOLUME</code>, <code>ENV</code> &#x7B49;) &#x5C06;&#x4F1A;&#x81EA;&#x52A8;&#x88AB;&#x83B7;&#x53D6;&#xFF0C;&#x65E0;&#x9700;&#x5728; <code>docker-compose.yml</code> &#x4E2D;&#x91CD;&#x590D;&#x8BBE;&#x7F6E;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x5206;&#x522B;&#x4ECB;&#x7ECD;&#x5404;&#x4E2A;&#x6307;&#x4EE4;&#x7684;&#x7528;&#x6CD5;&#x3002;</p>
<h2 id="build"><code>build</code></h2>
<p>&#x6307;&#x5B9A; <code>Dockerfile</code> &#x6240;&#x5728;&#x6587;&#x4EF6;&#x5939;&#x7684;&#x8DEF;&#x5F84;&#xFF08;&#x53EF;&#x4EE5;&#x662F;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#xFF0C;&#x6216;&#x8005;&#x76F8;&#x5BF9; docker-compose.yml &#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#xFF09;&#x3002; <code>Compose</code> &#x5C06;&#x4F1A;&#x5229;&#x7528;&#x5B83;&#x81EA;&#x52A8;&#x6784;&#x5EFA;&#x8FD9;&#x4E2A;&#x955C;&#x50CF;&#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x955C;&#x50CF;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&apos;3&apos;</span>
<span class="hljs-attr">services:</span>

<span class="hljs-attr">  webapp:</span>
<span class="hljs-attr">    build:</span> ./dir
</code></pre>
<p>&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>context</code> &#x6307;&#x4EE4;&#x6307;&#x5B9A; <code>Dockerfile</code> &#x6240;&#x5728;&#x6587;&#x4EF6;&#x5939;&#x7684;&#x8DEF;&#x5F84;&#x3002;</p>
<p>&#x4F7F;&#x7528; <code>dockerfile</code> &#x6307;&#x4EE4;&#x6307;&#x5B9A; <code>Dockerfile</code> &#x6587;&#x4EF6;&#x540D;&#x3002;</p>
<p>&#x4F7F;&#x7528; <code>arg</code> &#x6307;&#x4EE4;&#x6307;&#x5B9A;&#x6784;&#x5EFA;&#x955C;&#x50CF;&#x65F6;&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&apos;3&apos;</span>
<span class="hljs-attr">services:</span>

<span class="hljs-attr">  webapp:</span>
<span class="hljs-attr">    build:</span>
<span class="hljs-attr">      context:</span> ./dir
<span class="hljs-attr">      dockerfile:</span> Dockerfile-alternate
<span class="hljs-attr">      args:</span>
<span class="hljs-attr">        buildno:</span> <span class="hljs-number">1</span>
</code></pre>
<p>&#x4F7F;&#x7528; <code>cache_from</code> &#x6307;&#x5B9A;&#x6784;&#x5EFA;&#x955C;&#x50CF;&#x7684;&#x7F13;&#x5B58;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">build:</span>
<span class="hljs-attr">  context:</span> .
<span class="hljs-attr">  cache_from:</span>
<span class="hljs-attr">    - alpine:</span>latest
<span class="hljs-bullet">    -</span> corp/web_app:<span class="hljs-number">3.14</span>
</code></pre>
<h2 id="capadd-capdrop"><code>cap_add, cap_drop</code></h2>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x7684;&#x5185;&#x6838;&#x80FD;&#x529B;&#xFF08;capacity&#xFF09;&#x5206;&#x914D;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x8BA9;&#x5BB9;&#x5668;&#x62E5;&#x6709;&#x6240;&#x6709;&#x80FD;&#x529B;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">cap_add:</span>
<span class="hljs-bullet">  -</span> ALL
</code></pre>
<p>&#x53BB;&#x6389; NET_ADMIN &#x80FD;&#x529B;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">cap_drop:</span>
<span class="hljs-bullet">  -</span> NET_ADMIN
</code></pre>
<h2 id="command"><code>command</code></h2>
<p>&#x8986;&#x76D6;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x540E;&#x9ED8;&#x8BA4;&#x6267;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">command:</span> echo <span class="hljs-string">&quot;hello world&quot;</span>
</code></pre>
<h2 id="configs"><code>configs</code></h2>
<p>&#x4EC5;&#x7528;&#x4E8E; <code>Swarm mode</code>&#xFF0C;&#x8BE6;&#x7EC6;&#x5185;&#x5BB9;&#x8BF7;&#x67E5;&#x770B; <a href="../swarm_mode"><code>Swarm mode</code></a> &#x4E00;&#x8282;&#x3002;</p>
<h2 id="cgroupparent"><code>cgroup_parent</code></h2>
<p>&#x6307;&#x5B9A;&#x7236; <code>cgroup</code> &#x7EC4;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x5C06;&#x7EE7;&#x627F;&#x8BE5;&#x7EC4;&#x7684;&#x8D44;&#x6E90;&#x9650;&#x5236;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A; cgroup &#x7EC4;&#x540D;&#x79F0;&#x4E3A; <code>cgroups_1</code>&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">cgroup_parent:</span> cgroups_1
</code></pre>
<h2 id="containername"><code>container_name</code></h2>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x540D;&#x79F0;&#x3002;&#x9ED8;&#x8BA4;&#x5C06;&#x4F1A;&#x4F7F;&#x7528; <code>&#x9879;&#x76EE;&#x540D;&#x79F0;_&#x670D;&#x52A1;&#x540D;&#x79F0;_&#x5E8F;&#x53F7;</code> &#x8FD9;&#x6837;&#x7684;&#x683C;&#x5F0F;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">container_name:</span> docker-web-container
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;: &#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x540D;&#x79F0;&#x540E;&#xFF0C;&#x8BE5;&#x670D;&#x52A1;&#x5C06;&#x65E0;&#x6CD5;&#x8FDB;&#x884C;&#x6269;&#x5C55;&#xFF08;scale&#xFF09;&#xFF0C;&#x56E0;&#x4E3A; Docker &#x4E0D;&#x5141;&#x8BB8;&#x591A;&#x4E2A;&#x5BB9;&#x5668;&#x5177;&#x6709;&#x76F8;&#x540C;&#x7684;&#x540D;&#x79F0;&#x3002;</p>
</blockquote>
<h2 id="deploy"><code>deploy</code></h2>
<p>&#x4EC5;&#x7528;&#x4E8E; <code>Swarm mode</code>&#xFF0C;&#x8BE6;&#x7EC6;&#x5185;&#x5BB9;&#x8BF7;&#x67E5;&#x770B; <a href="../swarm_mode"><code>Swarm mode</code></a> &#x4E00;&#x8282;</p>
<h2 id="devices"><code>devices</code></h2>
<p>&#x6307;&#x5B9A;&#x8BBE;&#x5907;&#x6620;&#x5C04;&#x5173;&#x7CFB;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">devices:</span>
<span class="hljs-bullet">  -</span> <span class="hljs-string">&quot;/dev/ttyUSB1:/dev/ttyUSB0&quot;</span>
</code></pre>
<h2 id="dependson"><code>depends_on</code></h2>
<p>&#x89E3;&#x51B3;&#x5BB9;&#x5668;&#x7684;&#x4F9D;&#x8D56;&#x3001;&#x542F;&#x52A8;&#x5148;&#x540E;&#x7684;&#x95EE;&#x9898;&#x3002;&#x4EE5;&#x4E0B;&#x4F8B;&#x5B50;&#x4E2D;&#x4F1A;&#x5148;&#x542F;&#x52A8; <code>redis</code> <code>db</code> &#x518D;&#x542F;&#x52A8; <code>web</code></p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&apos;3&apos;</span>

<span class="hljs-attr">services:</span>
<span class="hljs-attr">  web:</span>
<span class="hljs-attr">    build:</span> .
<span class="hljs-attr">    depends_on:</span>
<span class="hljs-bullet">      -</span> db
<span class="hljs-bullet">      -</span> redis

<span class="hljs-attr">  redis:</span>
<span class="hljs-attr">    image:</span> redis

<span class="hljs-attr">  db:</span>
<span class="hljs-attr">    image:</span> postgres
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;<code>web</code> &#x670D;&#x52A1;&#x4E0D;&#x4F1A;&#x7B49;&#x5F85; <code>redis</code> <code>db</code> &#x300C;&#x5B8C;&#x5168;&#x542F;&#x52A8;&#x300D;&#x4E4B;&#x540E;&#x624D;&#x542F;&#x52A8;&#x3002;</p>
</blockquote>
<h2 id="dns"><code>dns</code></h2>
<p>&#x81EA;&#x5B9A;&#x4E49; <code>DNS</code> &#x670D;&#x52A1;&#x5668;&#x3002;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">dns:</span> <span class="hljs-number">8.8</span><span class="hljs-number">.8</span><span class="hljs-number">.8</span>

<span class="hljs-attr">dns:</span>
<span class="hljs-bullet">  -</span> <span class="hljs-number">8.8</span><span class="hljs-number">.8</span><span class="hljs-number">.8</span>
<span class="hljs-bullet">  -</span> <span class="hljs-number">114.114</span><span class="hljs-number">.114</span><span class="hljs-number">.114</span>
</code></pre>
<h2 id="dnssearch"><code>dns_search</code></h2>
<p>&#x914D;&#x7F6E; <code>DNS</code> &#x641C;&#x7D22;&#x57DF;&#x3002;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">dns_search:</span> example.com

<span class="hljs-attr">dns_search:</span>
<span class="hljs-bullet">  -</span> domain1.example.com
<span class="hljs-bullet">  -</span> domain2.example.com
</code></pre>
<h2 id="tmpfs"><code>tmpfs</code></h2>
<p>&#x6302;&#x8F7D;&#x4E00;&#x4E2A; tmpfs &#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x5230;&#x5BB9;&#x5668;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">tmpfs:</span> /run
<span class="hljs-attr">tmpfs:</span>
<span class="hljs-bullet">  -</span> /run
<span class="hljs-bullet">  -</span> /tmp
</code></pre>
<h2 id="envfile"><code>env_file</code></h2>
<p>&#x4ECE;&#x6587;&#x4EF6;&#x4E2D;&#x83B7;&#x53D6;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF0C;&#x53EF;&#x4EE5;&#x4E3A;&#x5355;&#x72EC;&#x7684;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#x6216;&#x5217;&#x8868;&#x3002;</p>
<p>&#x5982;&#x679C;&#x901A;&#x8FC7; <code>docker-compose -f FILE</code> &#x65B9;&#x5F0F;&#x6765;&#x6307;&#x5B9A; Compose &#x6A21;&#x677F;&#x6587;&#x4EF6;&#xFF0C;&#x5219; <code>env_file</code> &#x4E2D;&#x53D8;&#x91CF;&#x7684;&#x8DEF;&#x5F84;&#x4F1A;&#x57FA;&#x4E8E;&#x6A21;&#x677F;&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#x3002;</p>
<p>&#x5982;&#x679C;&#x6709;&#x53D8;&#x91CF;&#x540D;&#x79F0;&#x4E0E; <code>environment</code> &#x6307;&#x4EE4;&#x51B2;&#x7A81;&#xFF0C;&#x5219;&#x6309;&#x7167;&#x60EF;&#x4F8B;&#xFF0C;&#x4EE5;&#x540E;&#x8005;&#x4E3A;&#x51C6;&#x3002;</p>
<pre><code class="lang-bash">env_file: .env

env_file:
  - ./common.env
  - ./apps/web.env
  - /opt/secrets.env
</code></pre>
<p>&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x6587;&#x4EF6;&#x4E2D;&#x6BCF;&#x4E00;&#x884C;&#x5FC5;&#x987B;&#x7B26;&#x5408;&#x683C;&#x5F0F;&#xFF0C;&#x652F;&#x6301; <code>#</code> &#x5F00;&#x5934;&#x7684;&#x6CE8;&#x91CA;&#x884C;&#x3002;</p>
<pre><code class="lang-bash"><span class="hljs-comment"># common.env: Set development environment</span>
PROG_ENV=development
</code></pre>
<h2 id="environment"><code>environment</code></h2>
<p>&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x6570;&#x7EC4;&#x6216;&#x5B57;&#x5178;&#x4E24;&#x79CD;&#x683C;&#x5F0F;&#x3002;</p>
<p>&#x53EA;&#x7ED9;&#x5B9A;&#x540D;&#x79F0;&#x7684;&#x53D8;&#x91CF;&#x4F1A;&#x81EA;&#x52A8;&#x83B7;&#x53D6;&#x8FD0;&#x884C; Compose &#x4E3B;&#x673A;&#x4E0A;&#x5BF9;&#x5E94;&#x53D8;&#x91CF;&#x7684;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x9632;&#x6B62;&#x6CC4;&#x9732;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">environment:</span>
<span class="hljs-attr">  RACK_ENV:</span> development
<span class="hljs-attr">  SESSION_SECRET:</span>

<span class="hljs-attr">environment:</span>
<span class="hljs-bullet">  -</span> RACK_ENV=development
<span class="hljs-bullet">  -</span> SESSION_SECRET
</code></pre>
<p>&#x5982;&#x679C;&#x53D8;&#x91CF;&#x540D;&#x79F0;&#x6216;&#x8005;&#x503C;&#x4E2D;&#x7528;&#x5230; <code>true|false&#xFF0C;yes|no</code> &#x7B49;&#x8868;&#x8FBE; <a href="https://yaml.org/type/bool.html" target="_blank">&#x5E03;&#x5C14;</a> &#x542B;&#x4E49;&#x7684;&#x8BCD;&#x6C47;&#xFF0C;&#x6700;&#x597D;&#x653E;&#x5230;&#x5F15;&#x53F7;&#x91CC;&#xFF0C;&#x907F;&#x514D; YAML &#x81EA;&#x52A8;&#x89E3;&#x6790;&#x67D0;&#x4E9B;&#x5185;&#x5BB9;&#x4E3A;&#x5BF9;&#x5E94;&#x7684;&#x5E03;&#x5C14;&#x8BED;&#x4E49;&#x3002;&#x8FD9;&#x4E9B;&#x7279;&#x5B9A;&#x8BCD;&#x6C47;&#xFF0C;&#x5305;&#x62EC;</p>
<pre><code class="lang-bash">y|Y|yes|Yes|YES|n|N|no|No|NO|<span class="hljs-literal">true</span>|True|TRUE|<span class="hljs-literal">false</span>|False|FALSE|on|On|ON|off|Off|OFF
</code></pre>
<h2 id="expose"><code>expose</code></h2>
<p>&#x66B4;&#x9732;&#x7AEF;&#x53E3;&#xFF0C;&#x4F46;&#x4E0D;&#x6620;&#x5C04;&#x5230;&#x5BBF;&#x4E3B;&#x673A;&#xFF0C;&#x53EA;&#x88AB;&#x8FDE;&#x63A5;&#x7684;&#x670D;&#x52A1;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x4EC5;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x5185;&#x90E8;&#x7AEF;&#x53E3;&#x4E3A;&#x53C2;&#x6570;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">expose:</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;3000&quot;</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;8000&quot;</span>
</code></pre>
<h2 id="externallinks"><code>external_links</code></h2>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x8BE5;&#x6307;&#x4EE4;&#x3002;</p>
</blockquote>
<p>&#x94FE;&#x63A5;&#x5230; <code>docker-compose.yml</code> &#x5916;&#x90E8;&#x7684;&#x5BB9;&#x5668;&#xFF0C;&#x751A;&#x81F3;&#x5E76;&#x975E; <code>Compose</code> &#x7BA1;&#x7406;&#x7684;&#x5916;&#x90E8;&#x5BB9;&#x5668;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">external_links:</span>
<span class="hljs-bullet"> -</span> redis_1
<span class="hljs-attr"> - project_db_1:</span>mysql
<span class="hljs-attr"> - project_db_1:</span>postgresql
</code></pre>
<h2 id="extrahosts"><code>extra_hosts</code></h2>
<p>&#x7C7B;&#x4F3C; Docker &#x4E2D;&#x7684; <code>--add-host</code> &#x53C2;&#x6570;&#xFF0C;&#x6307;&#x5B9A;&#x989D;&#x5916;&#x7684; host &#x540D;&#x79F0;&#x6620;&#x5C04;&#x4FE1;&#x606F;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">extra_hosts:</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;googledns:8.8.8.8&quot;</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;dockerhub:52.1.157.61&quot;</span>
</code></pre>
<p>&#x4F1A;&#x5728;&#x542F;&#x52A8;&#x540E;&#x7684;&#x670D;&#x52A1;&#x5BB9;&#x5668;&#x4E2D; <code>/etc/hosts</code> &#x6587;&#x4EF6;&#x4E2D;&#x6DFB;&#x52A0;&#x5982;&#x4E0B;&#x4E24;&#x6761;&#x6761;&#x76EE;&#x3002;</p>
<pre><code class="lang-bash">8.8.8.8 googledns
52.1.157.61 dockerhub
</code></pre>
<h2 id="healthcheck"><code>healthcheck</code></h2>
<p>&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x68C0;&#x67E5;&#x5BB9;&#x5668;&#x662F;&#x5426;&#x5065;&#x5EB7;&#x8FD0;&#x884C;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">healthcheck:</span>
<span class="hljs-attr">  test:</span> [<span class="hljs-string">&quot;CMD&quot;</span>, <span class="hljs-string">&quot;curl&quot;</span>, <span class="hljs-string">&quot;-f&quot;</span>, <span class="hljs-string">&quot;http://localhost&quot;</span>]
<span class="hljs-attr">  interval:</span> <span class="hljs-number">1</span>m30s
<span class="hljs-attr">  timeout:</span> <span class="hljs-number">10</span>s
<span class="hljs-attr">  retries:</span> <span class="hljs-number">3</span>
</code></pre>
<h2 id="image"><code>image</code></h2>
<p>&#x6307;&#x5B9A;&#x4E3A;&#x955C;&#x50CF;&#x540D;&#x79F0;&#x6216;&#x955C;&#x50CF; ID&#x3002;&#x5982;&#x679C;&#x955C;&#x50CF;&#x5728;&#x672C;&#x5730;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;<code>Compose</code> &#x5C06;&#x4F1A;&#x5C1D;&#x8BD5;&#x62C9;&#x53D6;&#x8FD9;&#x4E2A;&#x955C;&#x50CF;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">image:</span> ubuntu
<span class="hljs-attr">image:</span> orchardup/postgresql
<span class="hljs-attr">image:</span> a4bc65fd
</code></pre>
<h2 id="labels"><code>labels</code></h2>
<p>&#x4E3A;&#x5BB9;&#x5668;&#x6DFB;&#x52A0; Docker &#x5143;&#x6570;&#x636E;&#xFF08;metadata&#xFF09;&#x4FE1;&#x606F;&#x3002;&#x4F8B;&#x5982;&#x53EF;&#x4EE5;&#x4E3A;&#x5BB9;&#x5668;&#x6DFB;&#x52A0;&#x8F85;&#x52A9;&#x8BF4;&#x660E;&#x4FE1;&#x606F;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">labels:</span>
  com.startupteam.description: <span class="hljs-string">&quot;webapp for a startup team&quot;</span>
  com.startupteam.department: <span class="hljs-string">&quot;devops department&quot;</span>
  com.startupteam.release: <span class="hljs-string">&quot;rc3 for v1.0&quot;</span>
</code></pre>
<h2 id="links"><code>links</code></h2>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x8BE5;&#x6307;&#x4EE4;&#x3002;</p>
</blockquote>
<h2 id="logging"><code>logging</code></h2>
<p>&#x914D;&#x7F6E;&#x65E5;&#x5FD7;&#x9009;&#x9879;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">logging:</span>
<span class="hljs-attr">  driver:</span> syslog
<span class="hljs-attr">  options:</span>
<span class="hljs-attr">    syslog-address:</span> <span class="hljs-string">&quot;tcp://192.168.0.42:123&quot;</span>
</code></pre>
<p>&#x76EE;&#x524D;&#x652F;&#x6301;&#x4E09;&#x79CD;&#x65E5;&#x5FD7;&#x9A71;&#x52A8;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">driver:</span> <span class="hljs-string">&quot;json-file&quot;</span>
<span class="hljs-attr">driver:</span> <span class="hljs-string">&quot;syslog&quot;</span>
<span class="hljs-attr">driver:</span> <span class="hljs-string">&quot;none&quot;</span>
</code></pre>
<p><code>options</code> &#x914D;&#x7F6E;&#x65E5;&#x5FD7;&#x9A71;&#x52A8;&#x7684;&#x76F8;&#x5173;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">options:</span>
<span class="hljs-attr">  max-size:</span> <span class="hljs-string">&quot;200k&quot;</span>
<span class="hljs-attr">  max-file:</span> <span class="hljs-string">&quot;10&quot;</span>
</code></pre>
<h2 id="networkmode"><code>network_mode</code></h2>
<p>&#x8BBE;&#x7F6E;&#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#x3002;&#x4F7F;&#x7528;&#x548C; <code>docker run</code> &#x7684; <code>--network</code> &#x53C2;&#x6570;&#x4E00;&#x6837;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">network_mode:</span> <span class="hljs-string">&quot;bridge&quot;</span>
<span class="hljs-attr">network_mode:</span> <span class="hljs-string">&quot;host&quot;</span>
<span class="hljs-attr">network_mode:</span> <span class="hljs-string">&quot;none&quot;</span>
<span class="hljs-attr">network_mode:</span> <span class="hljs-string">&quot;service:[service name]&quot;</span>
<span class="hljs-attr">network_mode:</span> <span class="hljs-string">&quot;container:[container name/id]&quot;</span>
</code></pre>
<h2 id="networks"><code>networks</code></h2>
<p>&#x914D;&#x7F6E;&#x5BB9;&#x5668;&#x8FDE;&#x63A5;&#x7684;&#x7F51;&#x7EDC;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&quot;3&quot;</span>
<span class="hljs-attr">services:</span>

<span class="hljs-attr">  some-service:</span>
<span class="hljs-attr">    networks:</span>
<span class="hljs-bullet">     -</span> some-network
<span class="hljs-bullet">     -</span> other-network

<span class="hljs-attr">networks:</span>
<span class="hljs-attr">  some-network:</span>
<span class="hljs-attr">  other-network:</span>
</code></pre>
<h2 id="pid"><code>pid</code></h2>
<p>&#x8DDF;&#x4E3B;&#x673A;&#x7CFB;&#x7EDF;&#x5171;&#x4EAB;&#x8FDB;&#x7A0B;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x3002;&#x6253;&#x5F00;&#x8BE5;&#x9009;&#x9879;&#x7684;&#x5BB9;&#x5668;&#x4E4B;&#x95F4;&#xFF0C;&#x4EE5;&#x53CA;&#x5BB9;&#x5668;&#x548C;&#x5BBF;&#x4E3B;&#x673A;&#x7CFB;&#x7EDF;&#x4E4B;&#x95F4;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8FDB;&#x7A0B; ID &#x6765;&#x76F8;&#x4E92;&#x8BBF;&#x95EE;&#x548C;&#x64CD;&#x4F5C;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">pid:</span> <span class="hljs-string">&quot;host&quot;</span>
</code></pre>
<h2 id="ports"><code>ports</code></h2>
<p>&#x66B4;&#x9732;&#x7AEF;&#x53E3;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x4F7F;&#x7528;&#x5BBF;&#x4E3B;&#x7AEF;&#x53E3;&#xFF1A;&#x5BB9;&#x5668;&#x7AEF;&#x53E3; <code>(HOST:CONTAINER)</code> &#x683C;&#x5F0F;&#xFF0C;&#x6216;&#x8005;&#x4EC5;&#x4EC5;&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x7684;&#x7AEF;&#x53E3;&#xFF08;&#x5BBF;&#x4E3B;&#x5C06;&#x4F1A;&#x968F;&#x673A;&#x9009;&#x62E9;&#x7AEF;&#x53E3;&#xFF09;&#x90FD;&#x53EF;&#x4EE5;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">ports:</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;3000&quot;</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;8000:8000&quot;</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;49100:22&quot;</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">&quot;127.0.0.1:8001:8001&quot;</span>
</code></pre>
<p><em>&#x6CE8;&#x610F;&#xFF1A;&#x5F53;&#x4F7F;&#x7528; <code>HOST:CONTAINER</code> &#x683C;&#x5F0F;&#x6765;&#x6620;&#x5C04;&#x7AEF;&#x53E3;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x4F7F;&#x7528;&#x7684;&#x5BB9;&#x5668;&#x7AEF;&#x53E3;&#x5C0F;&#x4E8E; 60 &#x5E76;&#x4E14;&#x6CA1;&#x653E;&#x5230;&#x5F15;&#x53F7;&#x91CC;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x5F97;&#x5230;&#x9519;&#x8BEF;&#x7ED3;&#x679C;&#xFF0C;&#x56E0;&#x4E3A; <code>YAML</code> &#x4F1A;&#x81EA;&#x52A8;&#x89E3;&#x6790; <code>xx:yy</code> &#x8FD9;&#x79CD;&#x6570;&#x5B57;&#x683C;&#x5F0F;&#x4E3A; 60 &#x8FDB;&#x5236;&#x3002;&#x4E3A;&#x907F;&#x514D;&#x51FA;&#x73B0;&#x8FD9;&#x79CD;&#x95EE;&#x9898;&#xFF0C;&#x5EFA;&#x8BAE;&#x6570;&#x5B57;&#x4E32;&#x90FD;&#x91C7;&#x7528;&#x5F15;&#x53F7;&#x5305;&#x62EC;&#x8D77;&#x6765;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x683C;&#x5F0F;&#x3002;</em></p>
<h2 id="secrets"><code>secrets</code></h2>
<p>&#x5B58;&#x50A8;&#x654F;&#x611F;&#x6570;&#x636E;&#xFF0C;&#x4F8B;&#x5982; <code>mysql</code> &#x670D;&#x52A1;&#x5BC6;&#x7801;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&quot;3.1&quot;</span>
<span class="hljs-attr">services:</span>

<span class="hljs-attr">mysql:</span>
<span class="hljs-attr">  image:</span> mysql
<span class="hljs-attr">  environment:</span>
<span class="hljs-attr">    MYSQL_ROOT_PASSWORD_FILE:</span> /run/secrets/db_root_password
<span class="hljs-attr">  secrets:</span>
<span class="hljs-bullet">    -</span> db_root_password
<span class="hljs-bullet">    -</span> my_other_secret

<span class="hljs-attr">secrets:</span>
<span class="hljs-attr">  my_secret:</span>
<span class="hljs-attr">    file:</span> ./my_secret.txt
<span class="hljs-attr">  my_other_secret:</span>
<span class="hljs-attr">    external:</span> <span class="hljs-literal">true</span>
</code></pre>
<h2 id="securityopt"><code>security_opt</code></h2>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x6A21;&#x677F;&#x6807;&#x7B7E;&#xFF08;label&#xFF09;&#x673A;&#x5236;&#x7684;&#x9ED8;&#x8BA4;&#x5C5E;&#x6027;&#xFF08;&#x7528;&#x6237;&#x3001;&#x89D2;&#x8272;&#x3001;&#x7C7B;&#x578B;&#x3001;&#x7EA7;&#x522B;&#x7B49;&#xFF09;&#x3002;&#x4F8B;&#x5982;&#x914D;&#x7F6E;&#x6807;&#x7B7E;&#x7684;&#x7528;&#x6237;&#x540D;&#x548C;&#x89D2;&#x8272;&#x540D;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">security_opt:</span>
<span class="hljs-attr">    - label:</span>user:USER
<span class="hljs-attr">    - label:</span>role:ROLE
</code></pre>
<h2 id="stopsignal"><code>stop_signal</code></h2>
<p>&#x8BBE;&#x7F6E;&#x53E6;&#x4E00;&#x4E2A;&#x4FE1;&#x53F7;&#x6765;&#x505C;&#x6B62;&#x5BB9;&#x5668;&#x3002;&#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x4F7F;&#x7528;&#x7684;&#x662F; SIGTERM &#x505C;&#x6B62;&#x5BB9;&#x5668;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">stop_signal:</span> SIGUSR1
</code></pre>
<h2 id="sysctls"><code>sysctls</code></h2>
<p>&#x914D;&#x7F6E;&#x5BB9;&#x5668;&#x5185;&#x6838;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">sysctls:</span>
  net.core.somaxconn: <span class="hljs-number">1024</span>
  net.ipv4.tcp_syncookies: <span class="hljs-number">0</span>

<span class="hljs-attr">sysctls:</span>
<span class="hljs-bullet">  -</span> net.core.somaxconn=<span class="hljs-number">1024</span>
<span class="hljs-bullet">  -</span> net.ipv4.tcp_syncookies=<span class="hljs-number">0</span>
</code></pre>
<h2 id="ulimits"><code>ulimits</code></h2>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x7684; ulimits &#x9650;&#x5236;&#x503C;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x6307;&#x5B9A;&#x6700;&#x5927;&#x8FDB;&#x7A0B;&#x6570;&#x4E3A; 65535&#xFF0C;&#x6307;&#x5B9A;&#x6587;&#x4EF6;&#x53E5;&#x67C4;&#x6570;&#x4E3A; 20000&#xFF08;&#x8F6F;&#x9650;&#x5236;&#xFF0C;&#x5E94;&#x7528;&#x53EF;&#x4EE5;&#x968F;&#x65F6;&#x4FEE;&#x6539;&#xFF0C;&#x4E0D;&#x80FD;&#x8D85;&#x8FC7;&#x786C;&#x9650;&#x5236;&#xFF09; &#x548C; 40000&#xFF08;&#x7CFB;&#x7EDF;&#x786C;&#x9650;&#x5236;&#xFF0C;&#x53EA;&#x80FD; root &#x7528;&#x6237;&#x63D0;&#x9AD8;&#xFF09;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">  ulimits:</span>
<span class="hljs-attr">    nproc:</span> <span class="hljs-number">65535</span>
<span class="hljs-attr">    nofile:</span>
<span class="hljs-attr">      soft:</span> <span class="hljs-number">20000</span>
<span class="hljs-attr">      hard:</span> <span class="hljs-number">40000</span>
</code></pre>
<h2 id="volumes"><code>volumes</code></h2>
<p>&#x6570;&#x636E;&#x5377;&#x6240;&#x6302;&#x8F7D;&#x8DEF;&#x5F84;&#x8BBE;&#x7F6E;&#x3002;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x4E3A;&#x5BBF;&#x4E3B;&#x673A;&#x8DEF;&#x5F84;(<code>HOST:CONTAINER</code>)&#x6216;&#x8005;&#x6570;&#x636E;&#x5377;&#x540D;&#x79F0;(<code>VOLUME:CONTAINER</code>)&#xFF0C;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x8BBF;&#x95EE;&#x6A21;&#x5F0F; &#xFF08;<code>HOST:CONTAINER:ro</code>&#xFF09;&#x3002;</p>
<p>&#x8BE5;&#x6307;&#x4EE4;&#x4E2D;&#x8DEF;&#x5F84;&#x652F;&#x6301;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">volumes:</span>
<span class="hljs-bullet"> -</span> /var/lib/mysql
<span class="hljs-bullet"> -</span> cache/:/tmp/cache
<span class="hljs-bullet"> -</span> ~/configs:/etc/configs/:ro
</code></pre>
<p>&#x5982;&#x679C;&#x8DEF;&#x5F84;&#x4E3A;&#x6570;&#x636E;&#x5377;&#x540D;&#x79F0;&#xFF0C;&#x5FC5;&#x987B;&#x5728;&#x6587;&#x4EF6;&#x4E2D;&#x914D;&#x7F6E;&#x6570;&#x636E;&#x5377;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&quot;3&quot;</span>

<span class="hljs-attr">services:</span>
<span class="hljs-attr">  my_src:</span>
<span class="hljs-attr">    image:</span> mysql:<span class="hljs-number">8.0</span>
<span class="hljs-attr">    volumes:</span>
<span class="hljs-attr">      - mysql_data:</span>/var/lib/mysql

<span class="hljs-attr">volumes:</span>
<span class="hljs-attr">  mysql_data:</span>
</code></pre>
<h2 id="&#x5176;&#x5B83;&#x6307;&#x4EE4;">&#x5176;&#x5B83;&#x6307;&#x4EE4;</h2>
<p>&#x6B64;&#x5916;&#xFF0C;&#x8FD8;&#x6709;&#x5305;&#x62EC; <code>domainname, entrypoint, hostname, ipc, mac_address, privileged, read_only, shm_size, restart, stdin_open, tty, user, working_dir</code> &#x7B49;&#x6307;&#x4EE4;&#xFF0C;&#x57FA;&#x672C;&#x8DDF; <code>docker run</code> &#x4E2D;&#x5BF9;&#x5E94;&#x53C2;&#x6570;&#x7684;&#x529F;&#x80FD;&#x4E00;&#x81F4;&#x3002;</p>
<p>&#x6307;&#x5B9A;&#x670D;&#x52A1;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x540E;&#x6267;&#x884C;&#x7684;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">entrypoint:</span> /code/entrypoint.sh
</code></pre>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x4E2D;&#x8FD0;&#x884C;&#x5E94;&#x7528;&#x7684;&#x7528;&#x6237;&#x540D;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">user:</span> nginx
</code></pre>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x4E2D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">working_dir:</span> /code
</code></pre>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x4E2D;&#x641C;&#x7D22;&#x57DF;&#x540D;&#x3001;&#x4E3B;&#x673A;&#x540D;&#x3001;mac &#x5730;&#x5740;&#x7B49;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">domainname:</span> your_website.com
<span class="hljs-attr">hostname:</span> test
<span class="hljs-attr">mac_address:</span> <span class="hljs-number">08</span><span class="hljs-bullet">-00</span><span class="hljs-bullet">-27</span><span class="hljs-bullet">-00</span><span class="hljs-bullet">-0</span>C<span class="hljs-bullet">-0</span>A
</code></pre>
<p>&#x5141;&#x8BB8;&#x5BB9;&#x5668;&#x4E2D;&#x8FD0;&#x884C;&#x4E00;&#x4E9B;&#x7279;&#x6743;&#x547D;&#x4EE4;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">privileged:</span> <span class="hljs-literal">true</span>
</code></pre>
<p>&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x9000;&#x51FA;&#x540E;&#x7684;&#x91CD;&#x542F;&#x7B56;&#x7565;&#x4E3A;&#x59CB;&#x7EC8;&#x91CD;&#x542F;&#x3002;&#x8BE5;&#x547D;&#x4EE4;&#x5BF9;&#x4FDD;&#x6301;&#x670D;&#x52A1;&#x59CB;&#x7EC8;&#x8FD0;&#x884C;&#x5341;&#x5206;&#x6709;&#x6548;&#xFF0C;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E2D;&#x63A8;&#x8350;&#x914D;&#x7F6E;&#x4E3A; <code>always</code> &#x6216;&#x8005; <code>unless-stopped</code>&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">restart:</span> always
</code></pre>
<p>&#x4EE5;&#x53EA;&#x8BFB;&#x6A21;&#x5F0F;&#x6302;&#x8F7D;&#x5BB9;&#x5668;&#x7684; root &#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#xFF0C;&#x610F;&#x5473;&#x7740;&#x4E0D;&#x80FD;&#x5BF9;&#x5BB9;&#x5668;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">read_only:</span> <span class="hljs-literal">true</span>
</code></pre>
<p>&#x6253;&#x5F00;&#x6807;&#x51C6;&#x8F93;&#x5165;&#xFF0C;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x5916;&#x90E8;&#x8F93;&#x5165;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">stdin_open:</span> <span class="hljs-literal">true</span>
</code></pre>
<p>&#x6A21;&#x62DF;&#x4E00;&#x4E2A;&#x4F2A;&#x7EC8;&#x7AEF;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">tty:</span> <span class="hljs-literal">true</span>
</code></pre>
<h2 id="&#x8BFB;&#x53D6;&#x53D8;&#x91CF;">&#x8BFB;&#x53D6;&#x53D8;&#x91CF;</h2>
<p>Compose &#x6A21;&#x677F;&#x6587;&#x4EF6;&#x652F;&#x6301;&#x52A8;&#x6001;&#x8BFB;&#x53D6;&#x4E3B;&#x673A;&#x7684;&#x7CFB;&#x7EDF;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x548C;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>.env</code> &#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#xFF0C;&#x4E0B;&#x9762;&#x7684; Compose &#x6587;&#x4EF6;&#x5C06;&#x4ECE;&#x8FD0;&#x884C;&#x5B83;&#x7684;&#x73AF;&#x5883;&#x4E2D;&#x8BFB;&#x53D6;&#x53D8;&#x91CF; <code>${MONGO_VERSION}</code> &#x7684;&#x503C;&#xFF0C;&#x5E76;&#x5199;&#x5165;&#x6267;&#x884C;&#x7684;&#x6307;&#x4EE4;&#x4E2D;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-attr">version:</span> <span class="hljs-string">&quot;3&quot;</span>
<span class="hljs-attr">services:</span>

<span class="hljs-attr">db:</span>
<span class="hljs-attr">  image:</span> <span class="hljs-string">&quot;mongo:${MONGO_VERSION}&quot;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x6267;&#x884C; <code>MONGO_VERSION=3.2 docker-compose up</code> &#x5219;&#x4F1A;&#x542F;&#x52A8;&#x4E00;&#x4E2A; <code>mongo:3.2</code> &#x955C;&#x50CF;&#x7684;&#x5BB9;&#x5668;&#xFF1B;&#x5982;&#x679C;&#x6267;&#x884C; <code>MONGO_VERSION=2.8 docker-compose up</code> &#x5219;&#x4F1A;&#x542F;&#x52A8;&#x4E00;&#x4E2A; <code>mongo:2.8</code> &#x955C;&#x50CF;&#x7684;&#x5BB9;&#x5668;&#x3002;</p>
<p>&#x82E5;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x5B58;&#x5728; <code>.env</code> &#x6587;&#x4EF6;&#xFF0C;&#x6267;&#x884C; <code>docker-compose</code> &#x547D;&#x4EE4;&#x65F6;&#x5C06;&#x4ECE;&#x8BE5;&#x6587;&#x4EF6;&#x4E2D;&#x8BFB;&#x53D6;&#x53D8;&#x91CF;&#x3002;</p>
<p>&#x5728;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x65B0;&#x5EFA; <code>.env</code> &#x6587;&#x4EF6;&#x5E76;&#x5199;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#x3002;</p>
<pre><code class="lang-bash"><span class="hljs-comment"># &#x652F;&#x6301; # &#x53F7;&#x6CE8;&#x91CA;</span>
MONGO_VERSION=3.6
</code></pre>
<p>&#x6267;&#x884C; <code>docker-compose up</code> &#x5219;&#x4F1A;&#x542F;&#x52A8;&#x4E00;&#x4E2A; <code>mongo:3.6</code> &#x955C;&#x50CF;&#x7684;&#x5BB9;&#x5668;&#x3002;</p>
<h2 id="&#x53C2;&#x8003;&#x8D44;&#x6599;">&#x53C2;&#x8003;&#x8D44;&#x6599;</h2>
<ul>
<li><a href="https://docs.docker.com/compose/compose-file/" target="_blank">&#x5B98;&#x65B9;&#x6587;&#x6863;</a></li>
<li><a href="https://github.com/docker/awesome-compose" target="_blank">awesome-compose</a></li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="commands.html" class="navigation navigation-prev " aria-label="Previous page: 命令说明">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="django.html" class="navigation navigation-next " aria-label="Next page: 实战 Django">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Compose 模板文件","level":"1.14.5","depth":2,"next":{"title":"实战 Django","level":"1.14.6","depth":2,"path":"compose/django.md","ref":"compose/django.md","articles":[]},"previous":{"title":"命令说明","level":"1.14.4","depth":2,"path":"compose/commands.md","ref":"compose/commands.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"compose/compose_file.md","mtime":"2020-04-12T12:29:28.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-23T10:39:04.870Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

